export const NAVIGATE_TYPE = {
  SELF: "self", //应用本身
  OUTSIDE: "outside", //外链
  SERVICE_CHAT: "serviceChat", //企业客服
};
/*
params:
        type: ''--无,'self'--应用本身，'outside'--外联
        target: ，目
*/
export const callNavigateHook = ({ type, target }) => {
  switch (type) {
    case NAVIGATE_TYPE.SELF:
      uni.$u.route({
        url: target.path,
      });
      break;

    case NAVIGATE_TYPE.OUTSIDE:
      // #ifdef H5
      window.location.href = target.url;
      // #endif
      // #ifdef MP
      uni.$u.route({
        url: "pages/base/webview/index",
        params: {
          src: encodeURIComponent(target.url),
        },
      });
      // #endif
      break;

    case NAVIGATE_TYPE.SERVICE_CHAT:
      // #ifdef H5
      uni.showToast({
        title: "H5不支持企业客服", //提示文字
        icon: "none",
        duration: 2000, //显示时长
      });
      // #endif
      // #ifdef MP
      wx.openCustomerServiceChat({
        extInfo: {
          url: target.serviceChatUrl,
        },
        corpId: target.serviceChatID,
        success() {},
        fail(err) {
          console.log("不支持客服", err);
          uni.showToast({
            title: "当前无客服", //提示文字
            icon: "none",
            duration: 2000, //显示时长
          });
        },
      });
      // #endif
      break;

    default:
      break;
  }
};
